/* 
利用构造函数创建一幅扑克牌
*/


/* 
Deck:一副扑克牌
Poker:一张扑克牌 
*/


/**
 * 创建一张扑克牌  
 * @param {number} number  1-1，...,11-j,12-Q,13-K，14-小王，15—大王
 * @param {color} color    1-黑桃  2-红桃 3-梅花 4-方片
 */
function Poker(number, color) {
    this.number = number
    this.color = color

    this.print = function () {
        var colors = ['♠️', '♥️', '♣️', '♦️']
        var color = this.color ? colors[this.color - 1] : ''
        var numbers = ['A', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'joker', 'JOKER']
        var number = numbers[this.number - 1]

        console.log(color, number);

    }
}

// var pokers = []
// for (var i = 1; i <= 13; i++) {
//     for (k = 1; k <= 4; k++) {
//         var p = new Poker(i, k)  /* 每张扑克有4个花色 */
//         pokers.push(p) 
//     }
// }
// pokers.push(new Poker(14,0))
// pokers.push(new Poker(15,0))

// console.log(pokers);



/* 创建一副扑克牌 */
function Deck() {
    this.pokers = []                  //属于实例的一个属性
    for (var i = 1; i <= 13; i++) {
        for (k = 1; k <= 4; k++) {
            var p = new Poker(i, k)  /* 每张扑克有4个花色 */
            this.pokers.push(p)
        }
    }
    this.pokers.push(new Poker(14, 0))
    this.pokers.push(new Poker(15, 0))

    this.print = function () {
        for (let i = 0; i < this.pokers.length; i++) {
            this.pokers[i].print()
        }
    }
}

var deck = new Deck()
deck.print()



